package Control;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bo.GerarRelatorioBO;
import dto.Relatorio;

/**
 * Servlet implementation class GerarRelatorio
 */
@WebServlet("/GerarRelatorio")
public class GerarRelatorioControl extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GerarRelatorioControl() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String req = request.getParameter("tipoRequisicao");
		
		if(req.equals("gerarRelatorio")){
			
			String dataInicial = request.getParameter("datainicial");
			String dataFinal = request.getParameter("datafinal");
			GerarRelatorioBO bo = new GerarRelatorioBO();
			Iterator<Relatorio> lista = bo.validaDados(dataInicial, dataFinal);
			
			request.setAttribute("lista", lista);
			RequestDispatcher dispatcher = request.getRequestDispatcher("relatorio/gerarRelatorio.jsp");  
			dispatcher.forward(request, response);
		}else{
			
			List<Relatorio> lista = new ArrayList<Relatorio>();
			request.setAttribute("lista", lista.iterator());
			RequestDispatcher dispatcher = request.getRequestDispatcher("relatorio/gerarRelatorio.jsp");  
			dispatcher.forward(request, response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
